<?php
/**
 * Created by PhpStorm.
 * User: 火柴
 * Date: 2016/5/28
 * GitHub: https://github.com/huaiguoguo
 * Email: 290559038@qq.com
 * Time: 20:34
 */

use yii\bootstrap\ActiveForm;
use yii\helpers\ArrayHelper;
use yii\helpers\Html;
use common\models\Region;

?>


<div class="content_wrap">
    <span class="content_title">我的地址</span>

    <div class="content_from">
            <ul>
                <?php $form = ActiveForm::begin([
                                                    'enableClientScript' => false,
                                                    'action'             => ['', 'id'=>$model->id],
                                                    'method'             => 'post',
                                                    'layout'             => 'inline',
                                                    'options'            => ['class' => 'form-inline'],
                                                    'fieldConfig'        => [
                                                        'template' => "<span>{label}</span><p>{input}</p>{hint}\n{error}\n",
                                                    ]

                                                ]); ?>
                <li>
                    <?= $form->field($model, 'consignee')
                        ->textInput(['autofocus' => true, 'placeholder' => '如何称呼'])
                        ->label('联系人', ['class' => 'item_title'])
                    ?>
                </li>
                <li>
                    <?= $form->field($model, 'mobile')
                        ->textInput(['autofocus' => true, 'placeholder' => '你的手机号码'])
                        ->label('手机号码', ['class' => 'item_title'])
                    ?>
                </li>
                <li>

                    <?= $form->field($model, 'province', ['options'=>['class'=>'input-group']])
                        ->dropDownList(ArrayHelper::map($model->getRegion(), 'region_id', 'region_name'),
                                       [
                                           'style'    => 'width:150px',
                                           'data-type'=>1,
                                           'prompt'   => '请选择省',
                                           'onchange' => 'ChangeFunc($(this).val(), 1)',
                                       ])
                        ->label(''); ?>

                    <?= $form->field($model, 'city', ['options'=>['class'=>'input-group']])
                        ->dropDownList(ArrayHelper::map($model->getRegion(2, $model->province), 'region_id', 'region_name'),
                                       [
                                           'style'    => 'width:150px',
                                           'data-type'=>2,
                                           'prompt'   => '请选择市',
                                           'onchange' => 'ChangeFunc($(this).val(), 2)',
                                       ])
                        ->label(''); ?>

                    <?= $form->field($model, 'district', ['options'=>['class'=>'input-group']])
                        ->dropDownList(ArrayHelper::map($model->getRegion(3, $model->city), 'region_id', 'region_name'),
                                       [
                                           'style'    => 'width:150px',
                                           'prompt'   => '请选择县',
                                           'onchange' => '',
                                       ])
                        ->label(''); ?>
                </li>

                <li>
                    <?= $form->field($model, 'address')
                        ->textInput(['autofocus' => true, 'placeholder' => '你的手机号码'])
                        ->label('详细地址', ['class' => 'item_title'])
                    ?>
                </li>

                <li>
                    <?= Html::submitButton("保存", ['class' => 'btn submit']) ?>
                </li>
                <?php ActiveForm::end(); ?>
            </ul>
    </div>
</div>
<span class="clear"></span>


<!--提示窗结束-->
<?php $this->beginBlock('AjaxGetSelect'); ?>
<!--<script>-->
    
    
    var ChangeFunc = function (id, type) {
        $.post("/user/region-list.html", "id=" + id + "&csrf_frontend=" + csrf_frontend, function (data) {
            SuccessFuce(data, type);
        });
    }

    var SuccessFuce = function (data, type) {
        if (typeof data != 'object') {
            data = JSON.parse(data);
        }

        switch (type) {
            case 1:
                $("#useraddress-city").html("<option value=>请选择市</option>");
                $("#useraddress-city").append(data.data);
                $("#useraddress-district").html("<option value=>请选择县</option>");
                break;

            case 2:
                $("#useraddress-district").html("<option value=>请选择县</option>");
                $("#useraddress-district").append(data.data);
                break;
        }
    }




<?php $this->endBlock(); ?>
<?php $this->registerJs($this->blocks['AjaxGetSelect'], \yii\web\View::POS_END); ?>
